(function ($, document, window, undefined) {
    var macro_sql_arr = [];
    var macro_currentuser_arr = [];
    var w = window;
    var self;
    var MACRO = "macro";
    var FLOW_TYPE_FREE = 1;
    var FIELD_TYPE = {
        "CHECKBOX": "checkbox",
        "TEXT": "text",
        "SELECT": "select",
        "MACRO": "macro",
        "DATE_TIME": "DATE_TIME",
        "DATE": "DATE",
        "TEXTAREA": "textarea",
        "RADIO": "radio",
        "CALCULATOR": "CALCULATOR",
        "BUTTON": "BUTTON"
    };

    var MACRO_CODE = {
        MACRO_CURRENT_USER: "macro_current_user",// 当前用户
        MACRO_USER_SELECT: "macro_user_select",// 用户用户列表
        MACRO_USER_MULTI_SELECT_WIN: "macro_user_multi_select_win", // 多用户选择窗体
        MACRO_OPINION: "macro_opinion",
        LOWERTOUPPER: "lowerToUpper",
        MACRO_DEPT_SELECT: "macro_dept_select",
        MACRO_DEPT_SEL_WIN: "macro_dept_sel_win",
        MACRO_USER_SELECT_WIN: "macro_user_select_win",
        MACRO_NEST_SHEET: "nest_sheet",
        MACRO_NEST_TABLE: "nest_table",
        MACRO_SIGN: "macro_sign", // 签名框
        MACRO_SIGN_IMG: "macro_sign_img", // 图片签名框
        MACRO_SQL: "macro_sql",
        MACRO_LOCATION_CTL: "macro_location_ctl",   // 用于flowInitDetailForm
        MACRO_LOCATION_TD_CTL: "macro_location_td_ctl",   // 用于flowInitDetailForm
        MACRO_IMAGE: "macro_image",                 // 图像宏控件，手机端可拍照片
        MACRO_EMAIL: "macro_email_ctl",
        MACRO_MOBILE: "macro_mobile_ctl",
        MACRO_IDCARD: "macro_idcard_ctl",
        MACRO_WRITEPAD: "macro_writepad_ctl",
        MACRO_RATY: "macro_raty",
        MACRO_ATTACHMENT: "macro_attachment",
        MACRO_ATTACHMENTS: "macro_attachments",
        MACRO_MODULE_FIELD_SELECT: "module_field_select",
        MACRO_BARCODE: "macro_barcode",
        MACRO_QRCODE: "macro_qrcode",
        MACRO_LOCATION_MARK_CTL: "macro_location_mark_ctl",
        MACRO_LOCATION_MARK_TD_CTL: "macro_location_mark_td_ctl",
        MACRO_UPLOADER_CTL: "macro_uploader_ctl",
	    MACRO_PROVINCE_SELECT: "macro_province_select",
        MACRO_CITY_SELECT: "macro_city_select",
        MACRO_CURRENT_UNIT: "macro_current_unit",
        MACRO_PROGRESS_BAR_CTL: "macro_progress_bar_ctl",
        MACRO_WORKFLOW_CTL: "macro_workflow_ctl",
        MACRO_UEDITOR: "macro_ueditor",
        MACRO_COLOR_PICKER_CTL: "macro_color_picker_ctl",
        MACRO_WORKFLOW_MINE_SELECT: "macro_workflow_mine_select",	
        MACRO_FLOW_SELECT: "macro_flow_select",
        MACRO_MULTI_ROLE_SEL_WIN: "macro_multi_role_sel_win",
        MACRO_MOREDEPTCTL: "macro_moredeptctl",
    };

    var MACRO_TYPE = {
        MACRO_USER_SELECT_TYPE: "userSelect",
        MODULE_FIELD_SELECT: "ModuleFieldSelect",
        MACRO_LOCATION: "location",
        MACRO_LOCATION_TD: "locationTd",
        MACRO_LOCATION_MARK_TD: "locationMarkTd",
        MACRO_USER_MULTI_SEL: "userMultiSelect",
        MACRO_SELECTWIN: "selectWin",   // 部门选择，取自：宏控件.getControlType()
        MACRO_TYPE_IMAGE: "img",         // 图像宏控件 ImageCtl
        MACRO_TYPE_WRITEPAD: "writePad"
    };

    var skey;
    $.Form = $.Class.extend({
        init: function (element, options) {
            this.element = element,
                this.default = {
                    "formSelector": ".mui-input-group",
                    "ulSelector": ".mui-table-view"
                }
            this.options = $.extend(true, this.default, options);
            skey = this.options.skey;
        },
        initForms: function (actionId, flowId, fields, formCode, data, isMobileForbidDownload) { // 流程字段content
            var self = this;
            var formSelector = jQuery(self.options.formSelector);
            $.each(fields, function (index, item) {
                // console.log(item);
                var code = item.code;
                var text = item.text;
                var value = item.value;
                var desc = item.desc;
                var type = item.type;
                var macroType = '';
                var isReadonly = false;
                if ("macroType" in item) {
                    macroType = item.macroType;
                }
                var macroCode = '';
                if ("macroCode" in item) {
                    macroCode = item.macroCode;
                }
                var isHidden = item.isHidden;
                if (isHidden == "true") {
                    // return;
                }
                var isNull = false;
                var editable = false;
                if ("isNull" in item) {
                    isNull = item.isNull == "true";
                }
                if ("isCanNull" in item) {
                    isNull = item.isCanNull;
                }

                if ("editable" in item) {
                    editable = item.editable == "true" ? true : false;
                }
                if ("isEditable" in item) {
                    editable = item.isEditable;
                }
                if ("isReadonly" in item) {
                    isReadonly = item.isReadonly;
                }

                var divContent = "";
                var row_class = "mui-input-row";
                if (type == FIELD_TYPE.SELECT || macroType == FIELD_TYPE.SELECT) {
                    if (editable && !isReadonly) {
                        row_class = "mui-input-row mui-select";
                    }
                } else if (type == FIELD_TYPE.CHECKBOX) {
                    if (item.switch == 'true') {
                        row_class = "mui-input-row";
                    } else {
                        row_class = "mui-input-row mui-checkbox";
                    }
                } else if (type == FIELD_TYPE.BUTTON) {
                    row_class = "mui-input-row text-center";
                }
                if (macroCode == MACRO_CODE.MACRO_PROGRESS_BAR_CTL) {
                    row_class = "mui-input-row mui-input-range";
                }
                var title = "<span style='color:#000'>" + item.title + "</span>";
                var _dataIsNull = true;
                if (!isNull && editable) {
                    if (macroCode != MACRO_CODE.MACRO_NEST_SHEET && macroCode != MACRO_CODE.MACRO_NEST_TABLE) {
                        _dataIsNull = false;
                    } else {
                        _dataIsNull = false;
                    }
                    title += "<span style='color:red;'>*</span>";
                }
                divContent += '<div class="' + row_class + '" id="row_' + code + '" style="display:' + (isHidden=='true'?'none':'') + '" data-code="' + code + '" data-isNull=' + _dataIsNull + ' data-fieldtype=' + item.fieldType + '>';
                if (macroCode == MACRO_CODE.MACRO_PROGRESS_BAR_CTL) {
                    divContent += '	<label>' + title + '<span id="' + code + 'Label" style="margin-left:10px">' + value + '</span>%</label>';
                } else {
                    if (type != FIELD_TYPE.BUTTON) {
                        divContent += '	<label>' + title + '</label>';
                    }
                }
                // SQL宏控件的macroType为select
                if (type == FIELD_TYPE.TEXT || macroType == FIELD_TYPE.TEXT || macroCode == MACRO_CODE.MACRO_SQL) {
                    if (macroCode == MACRO_CODE.MACRO_CURRENT_USER) {// 当前用户
                        divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '"><input type="text" value="' + text + '" class="border0"  readonly="readonly" />'
                        macro_currentuser_arr.push(item);
                    }
                    else if (macroCode == MACRO_CODE.MACRO_CURRENT_UNIT) {
                        divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '"><input type="text" value="' + text + '" class="border0"  readonly="readonly" />'
                    }
                    else if (macroCode == MACRO_CODE.LOWERTOUPPER) {
                        // var readonly = editable ? "" : "readonly";
                        var readonly = "readonly";
                        divContent += '	<input type="text" name="' + code + '" id="' + code + '" value="' + value + '" class="mui-input-clear border0" lowerFieldCode="' +
                            desc + '" title="大小写转换" ' + readonly + ' />'
                    }
                    else if (macroCode == MACRO_CODE.MACRO_IDCARD) {
                        var readonly = editable ? "" : "readonly";
                        var cls = editable ? "" : "border0";
                        divContent += '	<input type="text" name="' + code + '" id="' + code + '" value="' + value + '" class="mui-input-clear ' +  cls + '" idCardBirthField="' +
                            desc + '" title="身份证" ' + readonly + ' />'
                    }
                    else if (macroCode == MACRO_CODE.MACRO_NEST_SHEET || macroCode == MACRO_CODE.MACRO_NEST_TABLE) {
                        var destForm = item.desc.destForm;
                        var sourceForm = item.desc.sourceForm;
                        var parentFields = item.desc.parentFields;
                        var moduleCode = "", pageType = "";
                        var cwsId = "";
                        console.log('destForm', destForm, 'self.options', self.options);
                        if ("moduleCode" in self.options) {
                            moduleCode = self.options.moduleCode;
                            if ("id" in self.options) {
                                cwsId = self.options.id;
                                if (cwsId == 0 || ('' + cwsId).indexOf('cws_rand_') == 0) {
                                    pageType = "add";
                                } else {
                                    pageType = "edit";
                                }
                            }
                            if (self.options.pageType) {
                                pageType = self.options.pageType;
                            }
                        }

                        // @TASK 必填处理
                        if (macroCode == MACRO_CODE.MACRO_NEST_SHEET)
                            divContent += '<div id="cwsNestTable_' + code + '"><input name="' + code + '" id="' + code + '" title="' + item.title + '" type="hidden"/></div>';
                        else
                            divContent += '<div id="nestTable_' + code + '"><input name="' + code + '" id="' + code + '" title="' + item.title + '" type="hidden"/></div>';
                        divContent += '<span class="mui-btn mui-btn-primary nestSheetSelect" parentModuleCode="' + moduleCode + '" cwsId="' + cwsId + '" pageType="' + pageType + '" destForm="' + destForm + '" sourceForm="' + sourceForm + '" flowId=' + flowId + ' actionId=' + actionId + ' code="' + code + '" parentFields="' + parentFields + '" editable="' + editable + '" style="margin: 5px;" >查看</span>';
                    }
                    else if (macroCode == MACRO_CODE.MACRO_SIGN) {
                        var clear_class = editable ? "mui-input-clear" : "border0";
                        var readonly = "readonly";
                        divContent += '	<input type="text" name="' + code + '" id="' + code + '" value="' + value + '"';
                        divContent += ' class="';
                        if (editable) {
                            divContent += 'signInput ';
                        }
                        divContent += clear_class + '" ' + readonly + ' />';
                    }
                    else if (macroCode == MACRO_CODE.MACRO_SIGN_IMG) {
                        divContent += '	<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '"/>';
                        divContent += '<div id="stampImg_' + code + '">';
                        var imgUrl = item.metaData;
                        if (imgUrl != "") {
                            var ext = imgUrl.substring(imgUrl.lastIndexOf(".") + 1).toLowerCase();
                            divContent += "<img id='" + code + "_img' class='stamp_img' style='width:160px' link='../../public/showImg.do?path=" + imgUrl + "' ext='" + ext + "' src='../../public/showImg.do?path=" + imgUrl + "' />";
                        }
                        divContent += "</div>";
                        if (editable && !isReadonly) {
                            divContent += '<span class="mui-btn mui-btn-primary sign-img-btn" data-code="' + code + '" style="margin: 5px;">签章</span>';
                        }
                    }
                    else if (macroCode == MACRO_CODE.MACRO_SQL) {
                        macro_sql_arr.push(item);
                        console.log('SQLCtl item', item);
                        var clear_class = editable ? "mui-input-clear" : "border0";
                        var readonly = editable ? "" : "readonly";
                        divContent += '	<input type="text" name="' + code + '" id="' + code + '" value="' + value + '" class="' + clear_class + '" ' + readonly + ' />';
                    }
                    else if (macroCode == MACRO_CODE.MACRO_PROGRESS_BAR_CTL) {
                        divContent += '<input id="' + code + '" name="' + code + '" type="range" min="0" max="100" value="' +  value + '"';
                        divContent += '   onchange="$(\'#' + code + 'Label\').text(mui(\'#' + code + '\')[0].value)">';
                    }
                    else if (macroCode == MACRO_CODE.MACRO_WORKFLOW_CTL) {
                        divContent += '<span class="flow-title" flowId="' + value + '">' + text + '</span>';
                    }
                    else if (macroCode == MACRO_CODE.MACRO_UPLOADER_CTL) {
                        divContent += "<input type=\"file\" id='" + code + "' name=\"" + code + "\" multiple class='uploader-ctl' style='display: none' accept=\"image/*\">";
                        console.log(code + ' editable', editable);
                        if (editable) {
                            divContent += "<ul class='mui-input-row uploader-img-area' uploaderCtl='" + code + "'><li class='img-box' style='border:0'><img class='uploader-capture-btn' src='../../static/images/camera.png'></li>";
                            if (text) {
                                var ary = eval(text);
                                for (var k in ary) {
                                    var json = ary[k];
                                    divContent += '<li class="img-box" fid="' + json.id + '" field="' + code + '" >';
                                    divContent += '<img class="img-box-img attFile" link="../../public/showImg.do?path=' + json.visualPath + '/' + json.diskName + '" ext="' + json.ext + '" src="../../public/showImg.do?path=' + json.visualPath + '/' + json.diskName + '" />';
                                    divContent += '<span class="btn-del-img"><img class="att_del" isimgbox="true" src="../../static/images/btn_del.png" isFlow="' + (flowId != -1) + '"></span>';
                                    divContent += '</li>';
                                }
                            }
                            divContent += "</ul>";
                        }
                    }
                    else {
                        // fieldType 价格型
                        var fieldType = item.fieldType;
                        var clear_class = editable ? "mui-input-clear" : "border0";
                        var readonly = editable ? "" : "readonly";
                        if (isReadonly) {
                            readonly = "readonly";
                        }
                        // 价格型
                        if (fieldType == 9 && value == '') {
                            divContent += '	<input type="text"  name="' + code + '" id="' + code + '" value="0.00" class="' + clear_class + '" ' + readonly + ' />';
                        } else {
                            divContent += '	<input type="text"  name="' + code + '" id="' + code + '" value="' + value + '" class="' + clear_class + '" ' + readonly + ' />';
                        }
                    }
                    divContent += "</div>";
                } else if (type == FIELD_TYPE.CALCULATOR) {
                    var formula = item.formula;
                    var digit = item.digit;
                    var isroundto5 = item.isroundto5;
                    var present = item.present;
                    divContent += '	<input type="text" isroundto5="' + isroundto5 + '" digit="' + digit + '" kind="CALCULATOR" readonly formula="' + formula + '" formCode="' + present + '" name="' + code + '" id="' + code + '" value="' + value + '" class="' + clear_class + ' border0"/> ';
                }
                else if (type == FIELD_TYPE.BUTTON) {
                    divContent += '<button script="' + escape(item.script) + '" name="' + code + '" id="' + code + '" flowId="' + flowId + '" class="btn-custom">' + item.title + '</button> ';
                }
                else if (type == FIELD_TYPE.DATE_TIME || type == FIELD_TYPE.DATE) {
                    var options = type == FIELD_TYPE.DATE_TIME ? "{}" : '{"type":"date"}';
                    var icon_class = type == FIELD_TYPE.DATE_TIME ? "iconfont icon-naozhong" : "iconfont icon-rili";
                    var data = value;
                    console.log('field', code, 'value', value, 'editable', editable, 'isReadonly', isReadonly);
                    if (editable) {
                        if (value === "CURRENT") {
                            data = type == FIELD_TYPE.DATE_TIME ? self.formatDateTime(new Date()) : self.formatDate(new Date());
                        }
                    } else {
                        if (value === "CURRENT") {
                            data = '';
                            // data = type == FIELD_TYPE.DATE_TIME ? self.formatDateTime(new Date()) : self.formatDate(new Date());
                        }
                    }
                    var cls = editable ? '' : 'border0';
                    divContent += '	<input type="text" name="' + code + '" id="' + code + '" kind="' + type + '" class="input-icon ' + cls + '" value="' + data + '" readonly="readonly" />';
                    if (editable && !isReadonly) {
                        divContent += '<a class="date_btn" data-options=' + options + '><span class="' + icon_class + '"></span> </a>'
                    }
                    divContent += "</div>";
                } else if (type == FIELD_TYPE.SELECT || macroType == FIELD_TYPE.SELECT) {
                    var options = item.options;
                    if (editable) {
                        if (macroCode == MACRO_CODE.MACRO_PROVINCE_SELECT) {
                            divContent += "<select name='" + code + "' id='" + code + "' onchange=\"ajaxShowCityCountry(this.value, '')\""
                        }
                        else if (macroCode == MACRO_CODE.MACRO_CITY_SELECT) {
                            divContent += "<select name='" + code + "' id='" + code + "' onchange=\"ajaxShowCityCountry('', this.value)\""
                        }
                        else {
                            divContent += "<select name='" + code + "' id='" + code + "'";
                        }
                        var isMulti = false;
                        if (macroCode == MACRO_CODE.MACRO_FLOW_SELECT) {
                            var json = null;
                            if (item.desc && item.desc.indexOf("{") == 0) {
                                json = $.parseJSON(item.desc);
                                if (json.isMulti) {
                                    isMulti = json.isMulti;
                                    divContent += " multiple='multiple'";
                                }
                            }
                            if (editable) {
                                // select2在ios上不起作用
                                // jQuery(function () {
                                //     jQuery('#' + code).select2();
                                // });
                            }
                        } else if (macroCode == MACRO_CODE.MACRO_MULTI_ROLE_SEL_WIN || macroCode == MACRO_CODE.MACRO_MOREDEPTCTL) {
                            isMulti = true;
                            divContent += " multiple='multiple'";
                        }
                        if (isReadonly) {
                            divContent += " onfocus='this.defaultIndex=this.selectedIndex;' onchange='this.selectedIndex=this.defaultIndex;' ";
                        }
                        divContent += ">";

                        console.log('options', options);
                        if (options && options.length > 0 && options[0].value) {
                            divContent += '<option></option>';
                        }

                        $.each(options, function (s_index, s_item) {
                            var o_text = '';
                            var o_val = '';
                            if ("name" in s_item) {
                                o_text = s_item.name;
                            }
                            if ("value" in s_item) {
                                o_val = s_item.value;
                            }
                            if ("deptCode" in s_item) {
                                o_val = s_item.deptCode;
                            }
                            if ("deptName" in s_item) {
                                o_text = s_item.deptName;
                            }
                            var disabled = editable ? "" : "disabled";
                            var selected = "";

                            if (value) {
                                if (isMulti) {
                                    var ary = value.split(',');
                                    for (var k in ary) {
                                        if (ary[k] == o_val) {
                                            selected = "selected";
                                            // jQuery(function() {
                                            //     jQuery('#' + code).find("option[value=" + o_val + "]")[0].selected = true;
                                            // })
                                        }
                                    }
                                } else {
                                    selected = o_val == value ? "selected" : "";
                                }
                            }

                            divContent += '<option value="' + o_val + '"' + selected + '' + disabled + '>' + o_text + '</option>'
                        })
                        divContent += "</select>"
                    }
                    else {
                        divContent += '<input id="' + code + '_show" type="text" readonly value="' + text + '" class="mui-input-clear border0"/>';
                        divContent += '<input name="' + code + '" id="' + code + '" type="hidden" value="' + value + '"/>';
                    }
                    divContent += "</div>";
                } else if (type == FIELD_TYPE.CHECKBOX) {
                    var checked = "1" == value ? "checked" : "";
                    if (item.switch == 'true') {
                        if (value == '1') {
                            divContent += '<div code="' + code + '" class="mui-switch mui-switch-mini mui-active mui-switch-blue">';
                        } else {
                            divContent += '<div class="mui-switch mui-switch-mini mui-switch-blue">';
                        }
                        divContent += '<div class="mui-switch-handle"></div>';
                        divContent += '</div>';
                        divContent += "</div>";
                        divContent += '<input name="' + code + '" id="' + code + '" value="1" type="checkbox" ' + checked + ' style="display:none"/>';
                    } else {
                        var disabled = (editable && !isReadonly) ? "" : "disabled";
                        divContent += '<input name="' + code + '" id="' + code + '" value="1" type="checkbox" ' + checked + ' ' + disabled + '/>';
                        divContent += "</div>";
                    }
                } else if (type == FIELD_TYPE.TEXTAREA || macroType == FIELD_TYPE.TEXTAREA) {
                    var readonly = editable ? "" : "readonly";
                    if (isReadonly) {
                        readonly = "readonly";
                    }
                    if (type == FIELD_TYPE.TEXTAREA || macroCode == MACRO_CODE.MACRO_UEDITOR) {
                        console.log('TEXTAREA or MACRO_UEDITOR name', code);
                        if (editable == "false" && value == "") {
                            formSelector.append(divContent);
                            return;
                        }
                        if (macroCode == MACRO_CODE.MACRO_UEDITOR) {
                            value = text ? text : "";
                        }
                        var cls = editable ? '' : 'border0';
                        var ph = editable ? '请输入内容' : '';
                        divContent += '<div class="div_opinion">';
                        divContent += '	<textarea id="' + code + '" name="' + code + '" class="' + cls + '" rows="5" placeholder="' + ph + '" ' + readonly + '>' + value + '</textarea>'
                        divContent += '</div>';
                        divContent += "</div>";
                    } else {
                        // 意见输入框
                        if (macroCode == MACRO_CODE.MACRO_OPINION) {
                            if (editable) {
                                var json = null;
                                var opinionTime = self.formatDateTime(new Date());
                                var isTimeEditable = false;
                                if (item.desc) {
                                    json = $.parseJSON(item.desc);
                                    isTimeEditable = json.isTimeEditable;
                                }

                                divContent += '<textarea id="' + code + '" name="' + code + '"  rows="5" placeholder="请输入审批意见" >' + (value.opinionContent || '') + '</textarea>'
                                divContent += '<div class="opinionContentBox">';
                                divContent += '<div class="opinionContent">';
                                divContent += '<div>';
                                if (!value.existStamp) {
                                    divContent += '<span class="name mui-h6">' + value.opinionRealName + '</span>';
                                    if (isTimeEditable) {
                                        divContent += '<div style="display: flex;justify-content: right;">';
                                        divContent += '<input type="text" name="' + code + '_opinion_time" id="testFromTime" kind="DATE_TIME" class="input-icon " value="' + opinionTime + '">';
                                        if (!isReadonly) {
                                            divContent += '<a class="date_btn" data-options="{}"><span class="iconfont icon-naozhong"></span></a>'
                                        }
                                        divContent += '</div>';
                                    } else {
                                        divContent += '<span class="date mui-h6">' + opinionTime + '</span>	';
                                    }
                                } else {
                                    divContent += '<span class="name mui-h6"><img class="sign-img" src="' + value.stampUrl + '&skey=' + self.options.skey + '"/></span>';
                                    if (isTimeEditable) {
                                        divContent += '<div style="display: flex;justify-content: right;">';
                                        divContent += '<input type="text" name="' + code + '_opinion_time" id="testFromTime" kind="DATE_TIME" class="input-icon " value="' + opinionTime + '">';
                                        if (!isReadonly) {
                                            divContent += '<a class="date_btn" data-options="{}"><span class="iconfont icon-naozhong"></span></a>'
                                        }
                                        divContent += '</div>';
                                    } else {
                                        divContent += '<span class="date mui-h6">' + opinionTime + '</span>	';
                                    }
                                }

                                divContent += '</div>';
                                divContent += '</div>';
                                divContent += '</div>';
                            }
                            $.each(text, function (index, item) {
                                var opinionContent = item.opinionContent;
                                if (opinionContent && opinionContent.length>0) {
                                    divContent += '<div class="opinionContentBox">';
                                    var opinionRealName = item.opinionRealName
                                    var opinionTime = item.opinionTime;
                                    divContent += '<div class="opinionContent">';
                                    divContent += '<h5 class="content_h5">' + opinionContent + '</h5>';
                                    divContent += '<div>';
                                    if (!item.existStamp) {
                                        divContent += '<span class="name mui-h6">' + opinionRealName + '</span><span class="date mui-h6">' + opinionTime + '</span>	';
                                    } else {
                                        divContent += '<span class="name mui-h6"><img class="sign-img" src="' + item.stampUrl + '&skey=' + self.options.skey + '"/></span><span class="date mui-h6">' + opinionTime + '</span>	';
                                    }
                                    divContent += '</div>'
                                    divContent += '</div>';
                                    divContent += '</div>';
                                }
                            });
                            divContent += '</div>';
                        }

                    }
                } else if (type == FIELD_TYPE.RADIO) {
                    var options = item.options;
                    var disabled = (editable && !isReadonly) ? "" : "disabled";
                    var mui_class = editable ? "mui-input-row mui-radio" : "mui-input-row mui-radio mui-disabled"
                    $.each(options, function (s_index, s_item) {
                        var o_text = '';
                        var o_val = '';
                        if ("name" in s_item) {
                            o_text = s_item.name;
                        }
                        if ("value" in s_item) {
                            o_val = s_item.value;
                        }
                        console.log(o_text, o_val, value);
                        var checked = o_val == value ? "checked" : "";
                        divContent += '<div opt="' + code + '" class="' + mui_class + '">'
                        divContent += '<label>' + o_text + '</label><input name="' + code + '" id="' + code + '" type="radio" value="' + o_val + '" ' + checked + ' ' + disabled + ' />'
                        divContent += '</div>'
                    })
                    divContent += "</div>";
                }
                else if (macroCode == MACRO_CODE.MACRO_ATTACHMENT) {
                    var clear_class = editable ? "mui-input-clear" : "";
                    var readonly = editable ? "" : "readonly";
                    var metaData = jQuery.parseJSON(item.metaData);
                    if (metaData.attachId) {
                        console.log('isMobileForbidDownload', isMobileForbidDownload);
                        if (metaData.previewUrl) {
                            divContent += '<a class="att_preview" isVideo="' + item.isVideo + '" type="' + metaData.type + '" attachName="' + metaData.attachName + '" style="margin-top:10px;float:left !important;" url="' + metaData.previewUrl + '">' + metaData.attachName + "</a>";
                            if (editable) {
                                divContent += '<a class="btn-att-remove att_del" fId="' + metaData.attachId + '" isFlow="' + (flowId != -1) + '">×</a>';
                            }
                        } else if (!isMobileForbidDownload) {
                            var skey = self.options.skey;
                            var url = "../../public/android/getFile.do?skey=" + skey + "&flowId=" + flowId + "&attachId=" + metaData.attachId;
                            divContent += "<a class='attFile' style='margin-top:10px;float:left !important;' link='" + url + "'>" + metaData.attachName + "</a>";
                        } else {
                            divContent += metaData.attachName;
                        }
                    }
                    if (editable) {
                        divContent += '	<input type="file" name="' + code + '" id="' + code + '" value="' + value + '" class="' + clear_class + '" ' + readonly + ' style="margin-top:15px" />';
                    }
                } else if (macroCode == MACRO_CODE.MACRO_ATTACHMENTS) {
                    console.log('macroCode', macroCode, 'meta', item.metaData);
                    var clear_class = editable ? "mui-input-clear" : "";
                    var readonly = editable ? "" : "readonly";
                    var arr = jQuery.parseJSON(item.metaData);
                    divContent += '<div id="attsBox' + code + '" class="atts-box" style="float:right">';
                    if (arr && arr.length>0) {
                        for (var i in arr) {
                            divContent += '<div style="margin: 5px 0">';
                            if (arr[i].previewUrl) {
                                divContent += '<a class="att_preview" isVideo="' + arr[i].isVideo + '" type="' + arr[i].type + '" attachName="' + arr[i].attachName + '" style="margin-top:10px;float:none !important;" url="' + arr[i].previewUrl + '">' + arr[i].attachName + "</a>";
                                if (editable) {
                                    divContent += '<a class="btn-att-remove att_del" fId="' + arr[i].attachId + '" isFlow="' + (flowId != -1) + '">×</a>';
                                }
                            } else if (!isMobileForbidDownload) {
                                var skey = self.options.skey;
                                var url = "../../public/android/getFile.do?skey=" + skey + "&flowId=" + flowId + "&attachId=" + arr[i].attachId;
                                divContent += "<a class='attFile' style='margin-top:10px;float:none !important;' link='" + url + "'>" + arr[i].attachName + "</a>";
                                if (editable) {
                                    divContent += '<a class="btn-att-remove att_del" fId="' + arr[i].attachId + '" isFlow="' + (flowId != -1) + '">×</a>';
                                }
                            } else {
                                divContent += arr[i].attachName
                                if (editable) {
                                    divContent += '<a class="btn-att-remove att_del" fId="' + arr[i].attachId + '" isFlow="' + (flowId != -1) + '">×</a>';
                                }
                            }
                            divContent += '</div>';
                        }
                    }
                    if (editable) {
                        divContent += '	<div><input type="file" name="' + code + '" id="' + code + '" value="' + value + '" class="atts-file ' + clear_class + '" ' + readonly + ' style="margin-top:15px" /><span code="' + code + '" class="file-plus">+</span></div>';
                    }
                    divContent += '</div>';
                }
                else if (macroCode == MACRO_CODE.MACRO_BARCODE) {
                    var readonly = editable ? "" : "readonly";
                    if (editable) {
                        divContent += '	<input type="text" name="' + code + '" id="' + code + '" value="' + value + '" class="mui-input-clear" ' + readonly + ' />';
                    }
                } else if (macroCode == MACRO_CODE.MACRO_QRCODE) {
                    var readonly = editable ? "" : "readonly";
                    if (editable) {
                        divContent += '	<input type="text" name="' + code + '" id="' + code + '" value="' + value + '" class="mui-input-clear" ' + readonly + ' />';
                    }
                }
                else if (macroCode == MACRO_CODE.MACRO_WORKFLOW_MINE_SELECT) {
                    if (editable && !isReadonly) {
                        divContent += '<span id="' + code + '_realshow" style="float:left;margin-top: 11px;color:blue" class="flow-mine-title" flowId="' + value + '">' + text + '</span>';
                        divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '" class="mui-input-clear" ' + readonly + ' />';
                        divContent += '<span class="mui-btn mui-btn-primary myflow-select" code="' + code + '" style="margin-top: 5px;" >选择</span>';
                    } else {
                        divContent += '<div id="' + code + '_realshow" class="flow-mine-title" style="color:blue" flowId="' + value + '">' + text + '</div>';
                        divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '">';
                    }
                }
                else if (macroType == MACRO_TYPE.MACRO_USER_SELECT_TYPE) {
                    if (macroCode == MACRO_CODE.MACRO_USER_SELECT_WIN) {
                        var json = null;
                        var limitDepts = '';
                        if (item.desc) {
                            json = $.parseJSON(item.desc);
                            if (json.limitDepts)
                                limitDepts = json.limitDepts;
                        }
                        var desc = '';
                        if (json != null) {
                            desc = JSON.stringify(item.desc);
                        }
                        var cls = editable ? '' : 'border0';
                        divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '" desc=\'' + desc + '\' macroCode="' + MACRO_CODE.MACRO_USER_SELECT_WIN + '">';
                        divContent += '<input type="text" value="' + text + '" id="' + code + '_realshow" class="input-icon ' + cls + '" readonly="readonly" />'
                        if (editable && !isReadonly) {
                            divContent += '<span class="mui-btn mui-btn-primary user-select-win" code=\'' + code + '\' limitDepts="' + limitDepts + '" style="margin-top: 5px;" >选择</span>';
                            /**divContent +='<a href="#modal" code="'+code+'" class="userSelect"><span class="iconfont icon-bk-user"></span></a>';**/
                        }
                    } else if (macroCode == MACRO_CODE.MACRO_USER_MULTI_SELECT_WIN) {
                        var json = null;
                        var limitDepts = '';
                        if (item.desc && item.desc.indexOf("{") == 0) {
                            json = $.parseJSON(item.desc);
                            if (json.limitDepts)
                                limitDepts = json.limitDepts;
                        }

                        divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '">';
                        var cls = editable ? '' : 'border0';
                        divContent += '<textarea type="text" id="' + code + '_realshow" class="input-icon ' + cls + '" style="height: 80px" readonly="readonly">' + text + '</textarea>';
                        if (editable && !isReadonly) {
                            divContent += '<span class="mui-btn mui-btn-primary user-multi-select-win" code=\'' + code + '\' limitDepts="' + limitDepts + '" style="margin-top: 5px;" >选择</span>';
                            /**divContent +='<a href="#modal" code="'+code+'" class="userSelect"><span class="iconfont icon-bk-user"></span></a>';**/
                        }
                    }
                } else if (macroType == MACRO_TYPE.MACRO_SELECTWIN) {
                    var cls = editable ? '' : 'border0';
                    divContent += '<input type="text" id="' + code + '_realshow" class="' + cls + '" value="' + text + '" readonly/>';
                    divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '" />';
                    if (editable && !isReadonly) {
                        divContent += '<span class="mui-btn mui-btn-primary dept-select-win" code=\'' + code + '\' style="margin-top: 5px;" >选择</span>';
                    }
                } else if (macroType == MACRO_TYPE.MODULE_FIELD_SELECT) {
                    var metaData = $.parseJSON(item.metaData);
                    var skey = self.options.skey;
                    var desc = JSON.stringify(item.desc);
                    var cls = editable ? '' : 'border0';
                    divContent += '<input type="text" id="' + code + '_realshow" class="' + cls + '" value="' + text + '" readonly/>';
                    divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '" />';
                    divContent += '<div style="clear: both;">';
                    if (editable && !isReadonly) {
                        divContent += '<span class="mui-btn mui-btn-primary moduleSelect" formCode="' + formCode + '" desc=\'' + desc + '\' code=\'' + code + '\' style="margin-top: 5px;" >选择</span>';
                    }
                    else {
                        // 查看
                        if (metaData.id) {
                            divContent += '<span class="mui-btn mui-btn-primary module-field-select" data-sourceformcode="' + item.desc.sourceFormCode + '" data-val="' + metaData.id + '">查看</span>';
                        }
                    }
                    divContent += '</div>';

                    // 来自于 requestParam 参数值的映射
                    console.log('metaData.fieldMapAry', metaData.fieldMapAry);
                    if (metaData.fieldMapAry) {
                        jQuery(document).ready(function () {
                            doneField(metaData.fieldMapAry, value, text, code);
                        });
                    }
                } else if (macroType == MACRO_TYPE.MACRO_LOCATION) {
                    var _arr = value.split(",");
                    var _text = "";
                    if (_arr.length == 3) {
                        _text = _arr[2];
                    }
                    var cls = editable ? '' : 'border0';
                    divContent += '<input type="text" id="' + code + '_realshow" value="' + _text + '" readonly class="input-icon ' +  cls + '" />';
                    divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '" />';
                    divContent += '<a><span class="mui-icon mui-icon-paperplane icon-location" data-code="' + code + '" data-val = "' + value + '"></span></a>'
                    if (editable) {
                        jQuery(function () {
                            if (value == undefined || value == "") {
                                // 进行浏览器定位
                                var geolocation = new BMap.Geolocation();
                                geolocation.getCurrentPosition(function (r) {
                                    // 定位成功事件
                                    if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                                        var point = new BMap.Point(r.point.lng, +r.point.lat);
                                        var lat = +r.point.lat;
                                        var lon = r.point.lng;

                                        // 百度地图API功能
                                        var geoc = new BMap.Geocoder();
                                        var point = new BMap.Point(lon, lat);
                                        geoc.getLocation(point, function (rs) {
                                            var addComp = rs.addressComponents;
                                            address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
                                            mui.toast("定位成功：" + address);
                                            jQuery('#' + code + '_realshow').val(address);
                                            jQuery('#' + code).val(lon + "," + lat + "," + address);
                                        });
                                    }
                                }, {enableHighAccuracy: true})
                            }
                        });
                    }
                }
                else if (macroType == MACRO_TYPE.MACRO_LOCATION_TD) {
                    var _arr = value.split(",");
                    var _text = "";
                    if (_arr.length == 3) {
                        _text = _arr[2];
                    }
                    var cls = editable ? '' : 'border0';
                    divContent += '<input type="text" id="' + code + '_realshow" value="' + _text + '" readonly class="input-icon ' + cls + '" />';
                    divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '" />';
                    divContent += '<a><span class="mui-icon mui-icon-paperplane icon-location-td" data-code="' + code + '" data-val = "' + value + '"></span></a>'
                    console.log('icon-location-td editable', editable, 'value', value);
                    if (editable) {
                        jQuery(function () {
                            if (!value) {
                                // 如采用天地图H5定位接口来实现，苹果手机获取不到天地图定位数据，据说加上https证书也不行
                                var fn = function (e) {
                                    console.log('this', this);
                                    console.log('e', e);
                                    if (!e.lnglat) {
                                        return;
                                    } else {
                                        console.error('定位失败');
                                    }
                                    //当前为移动端时
                                    if (this.getStatus() == 0) {
                                        console.log('获取定位坐标：' + e.lnglat.lng + ',' + e.lnglat.lat);
                                        let geocode = new T.Geocoder();
                                        geocode.getLocation(e.lnglat, function() {
                                            if (result.getStatus() == 0) {
                                                console.log('searchResult', result.getAddress());
                                                mui.toast("定位成功");
                                                lon = result.location.lon;
                                                lat = result.location.lat;
                                                jQuery('#' + code + '_realshow').val(result.getAddress());
                                                jQuery('#' + code).val(e.lnglat.lng + "," + e.lnglat.lat + "," + result.getAddress());
                                            } else {
                                                mui.toast('地图服务返回状态：' + result.getStatus());
                                            }
                                        });
                                    } else {
                                        console.warn('getCurrentPosition', this);
                                    }
                                };

                                // 创建定位对象
                                var lo = new T.Geolocation();
                                console.log('lo', lo);
                                lo.getCurrentPosition(fn);

                                var options = {
                                    enableHighAccuracy: true,
                                    timeout: 5000,//超时时间,以ms为单位
                                    maximumAge: 24 * 60 * 60 * 1000,//位置缓存时间,以ms为单位
                                }

                                if (navigator.geolocation) {
                                    navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
                                }
                                else {
                                    mui.toast("浏览器不支持H5定位!");
                                }

                                function onSuccess(position) {
                                    console.log('position', position);
                                    var coords = position.coords;
                                    let geocode = new T.Geocoder();
                                    geocode.getLocation(new T.LngLat(coords.longitude, coords.latitude), function() {
                                        if (result.getStatus() == 0) {
                                            console.log('searchResult', result.getAddress());
                                            mui.toast("定位成功");
                                            lon = result.location.lon;
                                            lat = result.location.lat;
                                            jQuery('#' + code + '_realshow').val(result.getAddress());
                                            jQuery('#' + code).val(e.lnglat.lng + "," + e.lnglat.lat + "," + result.getAddress());
                                        } else {
                                            mui.toast('地图服务返回状态：' + result.getStatus());
                                        }
                                    });
                                }

                                //失败时
                                function onError(error) {
                                    console.log(error);
                                    switch (error.code) {
                                        case 1:
                                            mui.toast("位置服务被拒绝，请部署为https连接");
                                            break;
                                        case 2:
                                            mui.toast("暂时获取不到位置信息");
                                            break;
                                        case 3:
                                            mui.toast("获取信息超时");
                                            break;
                                        case 4:
                                            mui.toast("未知错误");
                                            break;
                                    }
                                }
                            }
                        });
                    }
                }
                else if (macroType == MACRO_TYPE.MACRO_LOCATION_MARK_TD) {
                    var _arr = value.split(",");
                    var _text = "";
                    if (_arr.length == 3) {
                        _text = _arr[2];
                    }
                    var cls = editable ? '' : 'border0';
                    divContent += '<input type="text" id="' + code + '_realshow" value="' + _text + '" readonly class="input-icon ' + cls + '" />';
                    divContent += '<input type="hidden" name="' + code + '" id="' + code + '" value="' + value + '" />';
                    divContent += '<a><span class="mui-icon mui-icon-paperplane icon-location-td" editable="' + editable + '" data-code="' + code + '" data-val = "' + value + '"></span></a>'
                }
                else if (macroType==MACRO_TYPE.MACRO_TYPE_IMAGE) {
                    console.log('marcoCode=' + macroCode);
                    if (macroCode == MACRO_CODE.MACRO_RATY) {
                        divContent += "<span id='" + code + "_raty' style='margin-top: 15px; display: block; float: left'></span>";

                        var rootPath = self.getContextPath();
                        var ratyProp = {
                            number: 5,
                            path: rootPath + '/static/images/rate',
                            cancelHint: '取消',
                            hintList: ['一星级', '二星级', '三星级', '四星级', '五星级'],
                            hintList: ['one-star', 'two-star', 'three-star', 'fore-star', 'five-star']
                        };
                        if (isReadonly) {
                            ratyProp.readOnly = true;
                        }
                        ratyProp.start = value;

                        jQuery(function () {
                            window.setTimeout(function() {
                                console.log(ratyProp);
                                console.log('code=' + code);
                                jQuery('#' + code + '_raty').raty(ratyProp);
                                console.log(jQuery('#' + code + '_raty-score').attr('name'));
                                jQuery('#' + code + '_raty-score').attr('name', code);
                            }, 10);
                        });
                    }
                    else {
                        divContent += '<input id="' + code + '" name="' + code + '" type="hidden" value="' + value + '"/>';
                        // 如果不含有小数点，说明不是文件名，而是默认值，如200,200，表示限定的宽高值
                        if (value!="" && value.indexOf(".")!=-1) {
                            var ext = value.substring(value.lastIndexOf(".") + 1).toLowerCase();
                            divContent += "<img class='attFile' link='../../public/showImg.do?path=" + value + "' ext='" + ext + "' src='../../public/showImg.do?path=" + value + "' style='width:96%' />";
                        }
                        var isOnlyCamera = false;
                        if (desc.indexOf('{')==0) {
                            var descJson = $.parseJSON(desc);
                            isOnlyCamera = descJson.isOnlyCamera;
                        }
                        if (editable && !isReadonly) {
                            divContent += '<span class="mui-btn mui-btn-primary capture_btn" captureFieldName="' + code + '" isOnlyCamera="' + isOnlyCamera + '" style="margin: 5px;" >照片</span>';
                        }
                    }
                }
                else if (macroType==MACRO_TYPE.MACRO_TYPE_WRITEPAD) {
                    divContent += '<input id="' + code + '" name="' + code + '" type="hidden" value="' + value + '"/>';
                    divContent += '<div id="pad_' + code + '">';
                    if (value!="") {
                        var ext = value.substring(value.lastIndexOf(".") + 1).toLowerCase();
                        divContent += "<img id='" + code + "_img' class='attFile' link='../../public/showImg.do?path=" + value + "' ext='" + ext + "' src='../../public/showImg.do?path=" + value + "' />";
                    }
                    divContent += "</div>";
                    if (editable && !isReadonly) {
                        divContent += '<span class="mui-btn mui-btn-primary sign_btn" data-code="' + code + '" style="margin: 5px;" >签名</span>';
                    }
                }

                formSelector.append(divContent);

                // 因在flow_dispose.html中将mui.init放在了flowDisposeInit的后面，且flowDisposeInit中post改为同步，使得switch及滑块能够正常初始化，否则动态添加的 Switch 组件需要手动初始化，滑块range如何手动初始化尚未找到方法
                // mui('.mui-switch').switch();

                jQuery('.mui-switch').each(function() {
                    var code = jQuery(this).attr('code');
                    var that = this;
                    that.addEventListener("toggle", function (event) {
                        if (event.detail.isActive) {
                            jQuery('#' + code).prop('checked', true);
                        } else {
                            jQuery('#' + code).prop('checked', false);
                        }
                    })
                });

                // 如果是宏控件，则引入JS文件
                if (type == FIELD_TYPE.MACRO) {
                    // self.writeJS(self.getContextPath() + "/m/flow/macro/" + macroCode + ".jsp?skey=" + self.options.skey + "&flowId=" + flowId + "&fieldName=" + code + "&formCode=" + formCode + "&editable=" + editable);
                    setTimeout(function() {
                        getMacroJs(macroCode, self.options.skey, flowId, code, formCode, editable, 'edit');
                    }, 0);
                }
            });

            self.bindEvent(formCode, isMobileForbidDownload);
            if (macro_sql_arr.length > 0) {
                macroSqlInit(flowId, skey, macro_sql_arr, formCode);
            }
            if (macro_currentuser_arr.length>0) {
                macroCurrentUserInit(flowId, skey, macro_currentuser_arr, formCode);
            }

            console.log('initForms data', data);
            if (data) {
                // 绑定跟算式相关字段的change事件
                var funcRelatedOnChangeFields = data.funcRelatedOnChangeFields;
                if (funcRelatedOnChangeFields) {
                    for (var k in funcRelatedOnChangeFields) {
                        var json = funcRelatedOnChangeFields[k];
                        console.log('funcRelatedOnChangeFields json', json);
                        bindFuncFieldRelateChangeEvent(json.formCode, json.field, json.relateFields);
                    }
                }
            }
        },
        initAtStep: function (annex) {
            var ul = '<ul class="at_flow">'
            var li = '';
            $.each(annex, function (index, item) {
                var readDate = item.readDate;
                var result = item.result;
                var userName = item.userName;
                var defaut_avatar = item.gender == 0 ? '../images/avatar_male.png' : '../images/avatar_female.png';
                var photo = item.photo == '' ? defaut_avatar : '../../' + item.photo;
                li += '<li class="clearfix">'
                li += '<span class="time">' + readDate + '</span>';
                li += '<div class="contain" >';
                li += '<div>';
                li += '<div class="avaterDiv">';
                li += '<img src="' + photo + '" width="48" height="48" />';
                li += '</div>';
                li += ' <span class="userName">' + userName + '</span>';
                li += ' <span class="comment" />';
                li += '</div>';
                li += '<div class="content">' + result + '</div>'
                var annexs = item.annexs;
                if (annexs.length > 0) {
                    li += '<div class="reply_content">';
                    $.each(annexs, function (iIndex, iItem) {
                        var annexUser = iItem.annexUser;
                        var content = iItem.content;
                        var add_date = iItem.add_date;
                        li += '<div class="item_reply">';
                        li += '<span class="reply_name">' + annexUser + '</span>';
                        li += '<span class="reply_date text-right">' + add_date + '</span>'
                        li += '<div class="re_content">'
                        li += '<span>' + content + '</span>'
                        li += '</div>';
                        li += '</div>'
                    });
                    li += '</div>'
                }
                li += '</div>';
                li += '</li>'
            });
            ul += li;
            ul += '</ul>';
            return ul;
        },
        initItemCommonLi: function (title, value, code, type) {
            var isButton = type == FIELD_TYPE.BUTTON;
            var li = '';
            if (code != null) {
                li += ' <li class="mui-table-view-cell" id="row_' + code + '" style="display: ' + (isButton?'none':'') + '">';
            } else {
                li += ' <li class="mui-table-view-cell" style="display: ' + (isButton?'none':'') + '">';
            }
            li += ' <div class="mui-table">';
            li += ' <div class="mui-table-cell mui-col-xs-4">';
            li += ' <span class="mui-h5">' + title + '</span>';
            li += ' </div>'
            li += ' <div class="mui-table-cell mui-col-xs-6">';
            li += ' <span class="mui-h5">' + value + '</span>'
            li += ' </div>'
            li += ' </div>';
            li += '</li>';
            return li;
        },
        initFlowDetail: function (data) {
            var self = this;
            var ul = jQuery(self.options.ulSelector);
            var fields = data.result.fields;
            var flowTypeName = data.flowTypeName;
            var status = data.status;
            var createDate = data.createDate;
            var sender = data.sender;
            var isMobileForbidDownload = data.isMobileForbidDownload
            ul.append(self.initItemCommonLi("流程名称", flowTypeName));
            ul.append(self.initItemCommonLi("发起人", sender));
            ul.append(self.initItemCommonLi("创建日期", createDate));
            ul.append(self.initItemCommonLi("状态", status));
            self.flowInitDetailForm(fields, isMobileForbidDownload); //加载流程表单

            if ("files" in data.result) {
                var _files = data.result.files;
                if (_files.length > 0) {
                    var isShowPage = true;
                    jQuery(".annex-group").before(self.flowInitFiles(_files, isShowPage, isMobileForbidDownload));
                }
            }

            jQuery(".mui-content").on("tap", ".attFile", function (e) {
                e.preventDefault();
                e.stopPropagation();
                var url = jQuery(this).attr("link");
                var ext = jQuery(this).attr("ext");
                if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp") {
                    var w=0, h=0;
                    console.log('tap attFile tagName', this.tagName);
                    if (this.tagName == "IMG") { // 图像宏控件
                        w = jQuery(this).width();
                        h = jQuery(this).height();
                    }
                    // 如果不延时调用showImg，则会导致photoswipe接收到点击在蒙版上的tap事件，从而调用close方法关闭预览
                    // 但是flow_dispose.html中却不需要延时处理
                    setTimeout(function() {
                        self.showImg(url, w, h);
                    }, 100)
                    return false;
                }

                if (isMobileForbidDownload)
                    return false;

                if (mui.os.plus) {
                    var btnArray = ['是', '否'];
                    mui.confirm('您确定要下载么？', '', btnArray, function(e) {
                        if (e.index == 0) {
                            var rootPath = self.getContextPath();
                            // 链接为../../public/android/flow/getFile，故需转换，否则会报400错误
                            var p = url.indexOf("/public/");
                            if (p!=-1) {
                                url = url.substring(p);
                            }
                            url = rootPath + url;
                            var dtask = plus.downloader.createDownload(url, {}, function (d, status) {
                                if (status == 200) {
                                    // 调用第三方应用打开文件
                                    plus.runtime.openFile(d.filename, {}, function (e) {
                                        alert('打开失败');
                                    });
                                } else {
                                    alert("下载失败: " + status);
                                }
                            });
                            dtask.start();
                        }
                    });
                }
                else {
                    let ua = navigator.userAgent;
                    if (ua.match(/MicroMessenger/i) == "MicroMessenger") {
                        wx.miniProgram.getEnv(function (res) {
                            console.log("当前环境：" + JSON.stringify(res));
                            console.log('url', url);
                            if (res.miniprogram) {
                                wx.miniProgram.navigateTo({
                                    // url: `/pages/application/wxDownload?url=${encodeURIComponent(url)}`
                                    // 需将绝对路径换成相对路径，否则点击下载后会报：{errMsg: “invokeMiniProgramAPI:ok“}
                                    url: `../application/wxDownload?url=${encodeURIComponent(url)}`
                                })
                            } else {
                                mui.openWindow({
                                    "url": url
                                })
                            }
                        });
                    } else {
                        mui.openWindow({
                            "url": url
                        })
                    }
                }

                return false;
            });
            $(".mui-content").on('tap', '.att_download', function (event) {
                var elem = this;
                var li = elem.parentNode.parentNode;
                var url = jQuery(li).find('.attFile').attr('link');
                if (!url) {
                    url = jQuery(li).find('.att_preview').attr('link');
                }

                if (mui.os.plus) {
                    var btnArray = ['是', '否'];
                    mui.confirm('您确定要下载么？', '', btnArray, function(e) {
                        if (e.index == 0) {
                            /*var rootPath = self.getContextPath();
                            // 链接为../../public/android/flow/getFile，故需转换，否则会报400错误
                            var p = url.indexOf("/public/");
                            if (p!=-1) {
                                url = url.substring(p);
                            }
                            // url = rootPath + url;
                            console.log('url', url);
                            uni.navigateTo({
                                url: `/application/download?url=${encodeURIComponent(url)}`
                                // url: `/application/download?record=${JSON.stringify({url: url, skey: self.options.skey})}`
                            });*/

                            var rootPath = self.getContextPath();
                            // 链接为../../public/android/flow/getFile，故需转换，否则会报400错误
                            var p = url.indexOf("/public/");
                            if (p!=-1) {
                                url = url.substring(p);
                            }
                            url = rootPath + url;
                            var dtask = plus.downloader.createDownload(url, {}, function (d, status) {
                                if (status == 200) {
                                    // 调用第三方应用打开文件
                                    plus.runtime.openFile(d.filename, {}, function (e) {
                                        alert('打开失败');
                                    });
                                } else {
                                    alert("下载失败: " + status);
                                }
                            });
                            dtask.start();

                            /*//打开加载框
                            // uni.showLoading();
                            //文件下载
                            uni.downloadFile({
                                url: url,
                                //设置请求头
                                header:{
                                    //设置请求格式，可以不要
                                    'content-type': 'application/json',
                                    "skey": self.options.skey
                                },
                                success: (res) => {
                                    console.log(res);
                                    if (res.statusCode === 200) {
                                        //隐藏加载框
                                        // uni.hideLoading();
                                        //文件保存到本地
                                        uni.saveFile({
                                            //临时路径
                                            tempFilePath: res.tempFilePath,
                                            //这里返回的参数res是文件的保存路径
                                            success: function(res) {
                                                // console.log('打印res',res)
                                                //提示框
                                                uni.showToast({
                                                    icon: 'success',
                                                    mask: true,
                                                    // title: '文件已保存：' + res.savedFilePath, //保存路径
                                                    title: '下载成功' ,
                                                    duration: 2000,
                                                });

                                                //自动打开文档查看
                                                setTimeout(() => {
                                                    var filePath = res.savedFilePath;
                                                    //新开页面打开文档，支持格式：doc, xls, ppt, pdf, docx, xlsx, pptx。
                                                    uni.openDocument({
                                                        filePath: filePath,
                                                        showMenu: true,
                                                        success: function (res) {
                                                            console.log('打开文档成功');
                                                        }
                                                    });
                                                }, 2000)
                                            }
                                        });
                                    }
                                },
                                fail:(err) => {
                                    uni.showToast({
                                        icon: 'none',
                                        mask: true,
                                        title: '失败请重新下载',
                                    });
                                }
                            });*/

                            /*var dtask = plus.downloader.createDownload(url, {}, function (d, status) {
                                if (status == 200) {
                                    // 调用第三方应用打开文件
                                    plus.runtime.openFile(d.filename, {}, function (e) {
                                        alert('打开失败');
                                    });
                                } else {
                                    alert("下载失败: " + status);
                                }
                            });
                            dtask.start();*/
                        }
                    });
                }
                else {
                    let ua = navigator.userAgent;
                    if (ua.match(/MicroMessenger/i) == "MicroMessenger") {
                        wx.miniProgram.getEnv(function (res) {
                            console.log("当前环境：" + JSON.stringify(res));
                            if (res.miniprogram) {
                                wx.miniProgram.navigateTo({
                                    // url: `/pages/application/wxDownload?url=${encodeURIComponent(url)}`
                                    // 需将绝对路径换成相对路径，否则点击下载后会报：{errMsg: “invokeMiniProgramAPI:ok“}
                                    url: `../application/wxDownload?url=${encodeURIComponent(url)}`
                                })
                            } else {
                                mui.openWindow({
                                    "url": url
                                })
                            }
                        });
                    } else {
                        mui.openWindow({
                            "url": url
                        })
                    }
                }
            });

            $(".mui-content").on('tap', '.att_preview', function (event) {
                var elem = this;
                var isVideo = elem.getAttribute("isVideo")=='true';
                var type = elem.getAttribute("type");
                var preViewPage = type == 'pdf' ? 'previewPdf' : 'preview';
                console.log('mui.os.plus', mui.os.plus, 'elem', elem);
                var url = elem.getAttribute("url");
                if (url.indexOf('http') != 0) {
                    url = "../../" + url;
                }
                if (mui.os.plus) {
                    uni.navigateTo({
                        url: `/application/${preViewPage}?record=${JSON.stringify({url: encodeURIComponent(elem.getAttribute("url")), name: elem.getAttribute("attachName"), isVideo: isVideo})}`
                    });
                } else {
                    let ua = navigator.userAgent;
                    if (ua.match(/MicroMessenger/i) == "MicroMessenger") {
                        if (ua.indexOf('miniProgram') !== -1) {
                            console.log('在小程序WebView中打开');
                            wx.miniProgram.getEnv(function (res) {
                                console.log("当前环境：" + JSON.stringify(res));
                                if (res.miniprogram) {
                                    wx.miniProgram.navigateTo({
                                        // url: `/pages/application/wxDownload?url=${encodeURIComponent(url)}`
                                        // 需将绝对路径换成相对路径，否则点击下载后会报：{errMsg: “invokeMiniProgramAPI:ok“}
                                        url: `../application/${preViewPage}?record=${JSON.stringify({
                                            url: encodeURIComponent(elem.getAttribute("url")),
                                            name: elem.getAttribute("attachName"),
                                            isVideo: isVideo
                                        })}`
                                    })
                                } else {
                                    // mui.openWindow({
                                    //     "url": url
                                    // })
                                    uni.navigateTo({
                                        url: `/application/${preViewPage}?record=${JSON.stringify({
                                            url: encodeURIComponent(elem.getAttribute("url")),
                                            name: elem.getAttribute("attachName"),
                                            isVideo: isVideo
                                        })}`
                                    });
                                }
                            });
                        } else {
                            // uni.navigateTo({
                            //     url: `../application/${preViewPage}?record=${JSON.stringify({
                            //         url: encodeURIComponent(elem.getAttribute("url")),
                            //         name: elem.getAttribute("attachName"),
                            //         isVideo: isVideo
                            //     })}`
                            // });

                            console.log('elem.getAttribute("url")', elem.getAttribute("url"));
                            var url = `/application/${preViewPage}?record=${JSON.stringify({
                                url: encodeURIComponent(elem.getAttribute("url")),
                                name: elem.getAttribute("attachName"),
                                isVideo: isVideo
                            })}`
                            uni.navigateTo({
                                url: url
                            });
                        }
                    } else {
                        if (window.top != window) {
                            // uniapp的h5方式运行于webview中，还可以通过一些特征，进一步判断是否运行于uniapp的iframe内，如 window.top的body中是否含有class: uni-body
                            uni.navigateTo({
                                url: `/application/${preViewPage}?record=${JSON.stringify({url: encodeURIComponent(elem.getAttribute("url")), name: elem.getAttribute("attachName"), isVideo: isVideo})}`
                            });
                        } else {
                            // 纯 H5 运行，不在uniapp的webview内
                            mui.openWindow({
                                "url": url
                            })
                        }
                    }
                }
            });

            $(".mui-content").on('tap', '.flow-title', function (event) {
                var elem = this;
                if (elem.getAttribute("flowId")) {
                    if (mui.os.plus) {
                        uni.navigateTo({
                            url: `/application/processShow?record=${JSON.stringify({flowId: elem.getAttribute("flowId")})}`
                        });
                    } else {
                        // H5中没问题，app按下面的方式打开后，没有标题及后退按钮
                        mui.openWindow({
                            "url": "../../m/flow/flowShow?flowId=" + elem.getAttribute("flowId") + "&skey=" + skey
                        })
                    }
                }
            });

            // 此段放在mui.flow.wx.js的flowAttendDetail中
            /*if (!data.isRendWithoutViewRule) {
                if (data.viewJs) {
                    var s0 = document.createElement('script');
                    s0.text = data.viewJs;
                    document.body.appendChild(s0);
                }
            }*/

            if ("isReply" in data) {
                if (data.isReply) {
                    var annexGroup = '<ul class="mui-table-view reply-ul">';
                    var annexes = data.result.annexs;
                    $.each(annexes, function (index, item) {
                        annexGroup += '<li class="mui-table-view-cell">';
                        annexGroup += '	<div class="reply-header">';
                        annexGroup += '		<span class="reply-name">' + item.annexUser + '</span>';
                        // annexGroup += '     <span class="reply-progress">' + item.progress + '%</span>';
                        annexGroup += '		<span class="reply-date">' + item.add_date + '</span>';
                        annexGroup += '	</div>';
                        var content = highlightMentions(item.content);
                        annexGroup += '	<div class="reply-content">' + content + '</div>';
                        annexGroup += '</li>';
                    });
                    annexGroup += "</ul>";
                    jQuery('.reply-form').show();
                    jQuery('#progressLabel').text(data.progress);
                    jQuery('#progress').val(data.progress);
                    jQuery(".annex-group").append(annexGroup);
                }
            }

            var isLight = data.isLight;// 是不是@流程
            if (isLight) {
                jQuery(".mui-content").append(self.initAtStep(data.lightDetail));
            }
        },
        flowInitDetailForm: function (fields, isMobileForbidDownload) {
            var self = this;
            var skey = self.options.skey;
            var ul = jQuery(self.options.ulSelector);
            $.each(fields, function (index, item) {
                var li = '';
                var title = item.title;
                var type = item.type;
                // console.log('item', item);
                var value = item.value;
                var macroCode = item.macroCode;
                var code = item.code;
                if (macroCode == MACRO_CODE.MACRO_NEST_SHEET || macroCode == MACRO_CODE.MACRO_NEST_TABLE) {
                    var divContent = '';
                    var destForm = item.desc.destForm;
                    var sourceForm = item.desc.sourceForm;
                    var parentFields = item.desc.parentFields;
                    var flowId = 0;
                    var moduleCode = "";
                    var cwsId = 0;
                    var pageType = "flow";
                    if ("flowId" in self.options) {
                        flowId = self.options.flowId;
                    }
                    if ("moduleCode" in self.options) {
                        moduleCode = self.options.moduleCode;
                        pageType = "show";
                    }
                    if ("id" in self.options) {
                        cwsId = self.options.id;
                    }

                    divContent = '<span class="mui-btn mui-btn-primary nestSheetSelect" parentModuleCode="' + moduleCode + '" cwsId= "' + cwsId + '"  pageType="' + pageType + '" destForm="' + destForm + '" sourceForm="' + sourceForm + '" flowId=' + flowId + ' actionId=0  code="' + item.code + '" parentFields="' + parentFields + '" editable="false" style="margin: 5px;" >查看</span>';
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += '<span class="mui-h5">' + title + '</span>';
                    li += '</div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += divContent;
                    li += '</div>'
                    li += ' </div>';
                    li += '</li>';
                } else if (macroCode == MACRO_CODE.MACRO_OPINION) {
                    var divContent = '';
                    $.each(value, function (index2, item2) {
                        var opinionContent = item2.opinionContent;
                        if (opinionContent.length > 0) {
                            divContent += '<div class="opinionContentBox">';
                            var opinionRealName = item2.opinionRealName
                            var opinionTime = item2.opinionTime;
                            divContent += '<div class="opinionContent">';
                            divContent += '<h5 class="content_h5">' + opinionContent + '</h5>';
                            divContent += '<div>';
                            if (!item2.existStamp) {
                                divContent += '<span class="name mui-h6">' + opinionRealName + '</span><span class="date mui-h6">' + opinionTime + '</span>	';
                            } else {
                                divContent += '<span class="name mui-h6"><img class="sign-img" src="' + item2.stampUrl + '&skey=' + self.options.skey + '"/></span><span class="date mui-h6">' + opinionTime + '</span>	';
                            }
                            divContent += '</div>'
                            divContent += '</div>';
                            divContent += "</div>";
                        }
                    });
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += divContent;
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_MODULE_FIELD_SELECT) {
                    var metaData = jQuery.parseJSON(item.metaData);
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += '     ' + value;
                    li += ' </div>'
                    if (metaData.id) {
                        li += ' <div class="mui-table-cell mui-col-xs-2"><span class="mui-btn mui-btn-primary module-field-select" data-sourceformcode="' + item.desc.sourceFormCode + '" data-val="' + metaData.id + '">查看</span></div>'
                    }
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_IMAGE) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    var ext = value.substring(value.lastIndexOf(".") + 1).toLowerCase();
                    li += '     <img class="attFile" link="../../public/showImg.do?path=' + value + '" ext="' + ext + '" style="width:96%" src="../../public/showImg.do?path=' + value + '"/>';
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_UPLOADER_CTL) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += '<div class="mui-h5" style="margin-bottom:5px;">' + title + '</div>';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-10">';
                    if (value) {
                        var ary = eval(value);
                        for (var k in ary) {
                            var json = ary[k];
                            li += '<div class="mui-col-xs-4" style="float: left; padding-left: 5px">';
                            var ext = json.ext.toLowerCase();
                            if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp") {
                                li += '<img class="attFile" style="width: 100px; height: 100px" link="../../public/showImg.do?path=' + json.visualPath + '/' + json.diskName + '" ext="' + json.ext + '" src="../../public/showImg.do?path=' + json.visualPath + '/' + json.diskName + '"/>';
                            } else {
                                li += '<div class="attFile" style="width: 100px; height: 100px; border: 1px solid #ccc">' + json.name + '</div>';
                            }
                            li += '</div>';
                        }
                    }
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_WRITEPAD) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    console.log('macroCode', macroCode, 'value', value);
                    var ext = value.substring(value.lastIndexOf(".") + 1).toLowerCase();
                    li += '     <img class="attFile" link="../../public/showImg.do?path=' + item.val + '" ext="' + ext + '" style="width:96%" src="../../public/showImg.do?path=' + item.val + '"/>';
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                } else if (macroCode == MACRO_CODE.MACRO_EMAIL) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += '     ' + value;
                    li += ' </div>'
                    // li += ' <div class="mui-table-cell mui-col-xs-2"><a href="mailto:' + value + '" class="mui-icon mui-icon-email mui-pull-right" style="font-size:25px"></a></div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_MOBILE) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += '     ' + value;
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-2"><a href="tel:' + value + '" class="mui-icon mui-icon-phone mui-pull-right" style="font-size:25px"></a></div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_BARCODE) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += '     <img style="width:96%" src="' + item.image + '"/>';
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_QRCODE) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += '     <img style="width:96%" src="' + item.image + '"/>';
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_PROGRESS_BAR_CTL) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += '     ' + value + '%';
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_LOCATION_CTL || macroCode == MACRO_CODE.MACRO_LOCATION_MARK_CTL) {
                    var _arr = value.split(",");
                    var _text = value;
                    if (_arr.length == 3) {
                        _text = _arr[2];
                    }

                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += ' <span class="mui-h5">' + _text + '</span>'
                    li += ' <a><span class="mui-icon mui-icon-paperplane icon-location" data-code="' + code + '" data-val = "' + value + '"></span></a>'
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_WORKFLOW_CTL) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += '     <span class="flow-title" flowId="' + item.val + '">' + item.value + '</span>';
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_COLOR_PICKER_CTL) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += '     <span style="width: 25px; display:inline-block; background-color: ' + item.value + '">&nbsp;</span>';
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_LOCATION_TD_CTL || macroCode == MACRO_CODE.MACRO_LOCATION_MARK_TD_CTL) {
                    var _arr = value.split(",");
                    var _text = value;
                    if (_arr.length == 3) {
                        _text = _arr[2];
                    }

                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += ' <span class="mui-h5">' + _text + '</span>'
                    li += ' <a><span class="mui-icon mui-icon-paperplane icon-location-td" data-code="' + code + '" data-val = "' + value + '"></span></a>'
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_ATTACHMENT) {
                    if (item.metaData) {
                        var metaData = jQuery.parseJSON(item.metaData);
                        var _text = '';
                        if (metaData.attachId) {
                            if (metaData.previewUrl) {
                                _text = '<a class="att_preview" attachName="' + metaData.attachName + '" type="' + metaData.type + '" style="margin-top:10px;float:none !important;" url="' + metaData.previewUrl + '">' + metaData.attachName + "</a>";
                            } else if (!isMobileForbidDownload) {
                                var skey = self.options.skey;
                                var flowId = self.options.flowId;
                                var url = "../../public/android/getFile.do?skey=" + skey + "&flowId=" + flowId + "&attachId=" + metaData.attachId;
                                _text = "<a class='attFile' style='margin-top:10px;float:left !important;' link='" + url + "'>" + metaData.attachName + "</a>";
                            } else {
                                _text = metaData.attachName;
                            }
                        }
                    }

                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += ' <span class="mui-h5">' + _text + '</span>'
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_ATTACHMENTS) {
                    console.log('macroCode', macroCode, 'meta', item.metaData);
                    _text = '';
                    var arr = jQuery.parseJSON(item.metaData);
                    if (arr && arr.length>0) {
                        for (var i in arr) {
                            if (arr[i].previewUrl) {
                                _text += '<a class="att_preview" attachName="' + arr[i].attachName + '" type="' + arr[i].type + '" style="margin-top:10px;float:none !important;" url="' + arr[i].previewUrl + '">' + arr[i].attachName + "</a>";
                            } else if (!isMobileForbidDownload) {
                                var skey = self.options.skey;
                                var url = "../../public/android/getFile.do?skey=" + skey + "&flowId=" + arr[i].flowId + "&attachId=" + arr[i].attachId;
                                _text += "<a class='attFile' style='display:block;margin-top:10px;float:none !important;' link='" + url + "'>" + arr[i].attachName + "</a>";
                            } else {
                                _text += arr[i].attachName + "<br/>";
                            }
                        }
                    }
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += ' <span class="mui-h5">' + _text + '</span>'
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_UEDITOR) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-h5" style="margin-bottom:5px;">' + title + '</div>';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-10">';
                    var $obj;
                    try {
                        $obj = jQuery(value);
                    } catch (e) {
                        console.error(e);
                    }
                    if ($obj && $obj.find('video')[0]) {
                        $obj = $obj.find('video').css({"width": "98%", "height": window.screen.width * 0.98 * 0.66 + "px"});
                        li += $obj.prop('outerHTML');
                    } else {
                        li += value;
                    }
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else if (macroCode == MACRO_CODE.MACRO_WORKFLOW_MINE_SELECT) {
                    li += ' <li class="mui-table-view-cell" id="row_' + code + '">';
                    li += ' <div class="mui-table">';
                    li += ' <div class="mui-table-cell mui-col-xs-4">';
                    li += ' <span class="mui-h5">' + title + '</span>';
                    li += ' </div>'
                    li += ' <div class="mui-table-cell mui-col-xs-6">';
                    li += ' <div id="' + code + '_realshow" class="flow-mine-title" style="color:blue" flowId="' + item.val + '">' + item.value + '</div>';
                    li += ' </div>'
                    li += ' </div>';
                    li += '</li>';
                }
                else {
                    li = self.initItemCommonLi(title, value, code, type);
                }

                ul.append(li);
            });

            $(".mui-table-view-cell").on("tap", ".icon-location", function () {
                openBaiduMap(this, skey);
            });
            $(".mui-table-view-cell").on("tap", ".icon-location-td", function () {
                openTdMap(this, skey);
            });
            $(".mui-table-view-cell").on("tap", ".nestSheetSelect", function () {
                openNestSheet(this, skey);
            });
            $(".mui-table-view-cell").on("tap", ".module-field-select", function () {
                openModuleShow(this, skey);
            });
            $(".mui-table-view-cell").on("tap", ".flow-mine-title", function() {
                var flowId = jQuery(this).attr('flowId');
                mui.openWindow('../flow/flowShow?skey=' + skey + '&flowId=' + flowId + '&isUniWebview=' + self.options.isUniWebview);
            });
        },
        flowInitFiles: function (files, isShowPage, isMobileForbidDownload) {
            var self = this;
            var _ul = '<ul class="mui-table-view mui-table-view-chevron att_ul" >'
            _ul += '<li class="mui-table-view-cell mui-media ">附件列表：</li>';
            $.each(files, function (index, item) {
                var _id = -1;
                var canDel = false;
                var isFlow = false;
                // 如果是流程中，则含有canDel，如果是模块中，则不含有
                if ("canDel" in item) {
                    canDel = item.canDel;
                    isFlow = true;
                    if ("id" in item) {
                        _id = item.id;
                    }
                } else {
                    _id = item.id;
                    canDel = true;
                }
                // 如果是显示页，如flow_modify.jsp
                if (isShowPage) {
                    canDel = false;
                }
                var _name = item.name;
                var _size = item.size;
                var ext = _name.substring(_name.lastIndexOf(".") + 1).toLowerCase();
                var _imgUrl = self.getFileImg(ext);
                var _url = item.url + "&skey=" + self.options.skey;

                _ul += '<li class="mui-table-view-cell mui-media att_li" fId="' + _id + '">';
                _ul += '<div class="mui-slider-right mui-disabled">';
                if (canDel) {
                    _ul += '<a class="mui-btn mui-btn-red att_del" isFlow="' + isFlow + '">删除</a>';
                }
                if (item.previewUrl) {
                    _ul += '<a class="mui-btn mui-btn-blue att_preview" type="' + ext + '" attachName="' + _name + '" url="' + item.previewUrl + '" link="../../' + _url + '">预览</a>';
                }
                if (item.canDocInRed && !item.red) {
                    _ul += '<a attId="' + item.id + '" class="mui-btn mui-btn-red inRed">套红</a>';
                }
                if (item.canSeal/* && !item.sealed*/) {
                    _ul += '<a attId="' + item.id + '" class="mui-btn mui-btn-green seal">盖章</a>';
                }
                if (item.canCircleRead) {
                    _ul += '<a attId="' + item.id + '" class="mui-btn mui-btn-green circle_read">圈阅</a>';
                }
                if (!isMobileForbidDownload) {
                    _ul += '<a class="mui-btn mui-btn-yellow att_download">下载</a>';
                }
                _ul += '</div>';
                _ul += '<div class="mui-slider-handle">';
                if (item.previewUrl) {
                    _ul += '<a class="att_preview" type="' + ext + '" isVideo="' + item.isVideo + '" attachName="' + _name + '" url="' + item.previewUrl + '" link="../../' + _url + '">';
                }
                else if (!isMobileForbidDownload) {
                    _ul += '<a class="attFile" attId="' + _id + '" ext="' + ext + '" href="javascript:;" link="../../' + _url + '" >';
                }
                _ul += '<img class="mui-media-object mui-pull-left" src="../../weixin/images/file/' + _imgUrl + '" />';
                _ul += '<div class="mui-media-body">';
                _ul += _name;
                _ul += '</div>';
                if (item.previewUrl || !isMobileForbidDownload) {
                    _ul += '</a>';
                }
                _ul += '</div>';
                _ul += '</li>';
            });
            return _ul;
        },
        bindFileDel: function () {
            var self = this;
            var skey = self.options.skey;

            $(".mui-content").off('tap', '.att_del').on('tap', '.att_del', function (event) {
                var elem = this;
                var isAttList = false;
                var li;
                var fId = elem.getAttribute("fId"); // 表单中的文件或文件组控件中
                if (!fId) {
                    // 附件栏中
                    isAttList = true;
                    li = elem.parentNode.parentNode;
                    fId = li.getAttribute("fId");
                }

                var btnArray = ['确认', '取消'];
                var isFlow = jQuery(this).attr("isFlow");
                console.log('fId=' + fId);
                var isImgBox = elem.getAttribute("isImgBox");

                mui.confirm('确认删除该条记录？', '提示', btnArray, function (e) {
                    setTimeout(function () {
                        $.swipeoutClose(li);
                    }, 0);
                    if (e.index == 0) {
                        if (fId != "0") {
                            // console.log("isFlow=" + isFlow);
                            mui.get("../../public/android/module/attDel",
                                {"skey": skey, "id": fId, "isFlow": isFlow}, function (data) {
                                    var res = data.res;
                                    var msg = data.msg;
                                    if (res == "0") {
                                        $.toast("删除成功!");
                                        if (isAttList) {
                                            li.parentNode.removeChild(li);
                                            var _pLen = jQuery(".att_li").length;
                                            if (_pLen == 0) {
                                                jQuery(".att_ul").remove();
                                            }
                                        } else {
                                            elem.parentNode.parentNode.removeChild(elem.parentNode);
                                        }
                                    } else {
                                        $.toast(msg);
                                    }
                                }, "json");
                        } else {
                            var _index;
                            console.log("isImgBox=" + isImgBox);
                            if (isImgBox == "true") {
                                // 如果是点击了预览图片框的删除按钮
                                _index = jQuery(li).index() - 1;
                                console.log("_index=" + _index);
                            }
                            else {
                                _index = jQuery(li).index() - 1;
                            }
                            blob_arr.splice(_index, 1);
                            li.parentNode.removeChild(li);
                            var _pLen = jQuery(".att_li").length;
                            if (_pLen == 0) {
                                jQuery(".att_ul").remove();
                            }
                        }
                    }
                });
            });

            console.log('Init att_preview tap event');

            // 用off防止重复绑定，因为在回复模型渲染的时候，事件会被绑定两次
            $(".mui-content").off('tap', '.att_preview').on('tap', '.att_preview', function (event) {
                var elem = this;
                console.log('mui.os.plus', mui.os.plus);

                var isVideo = elem.getAttribute("isVideo")=='true';
                var type = elem.getAttribute("type");
                var preViewPage = type == 'pdf' ? 'previewPdf' : 'preview';
                var url = elem.getAttribute("url");
                if (url.indexOf('http') != 0) {
                    url = "../../" + url;
                }
                if (mui.os.plus) {
                    uni.navigateTo({
                        url: `/application/${preViewPage}?record=${JSON.stringify({url: encodeURIComponent(elem.getAttribute("url")), name: elem.getAttribute("attachName"), isVideo: isVideo})}`
                    });
                } else {
                    let ua = navigator.userAgent;
                    console.log('userAgent', ua);
                    if (ua.match(/MicroMessenger/i) == "MicroMessenger") {
                        if (ua.indexOf('miniProgram') !== -1) {
                            console.log('在小程序WebView中打开');
                            wx.miniProgram.getEnv(function (res) {
                                console.log("当前环境：" + JSON.stringify(res));
                                if (res.miniprogram) {
                                    wx.miniProgram.navigateTo({
                                        // url: `/pages/application/wxDownload?url=${encodeURIComponent(url)}`
                                        // 需将绝对路径换成相对路径，否则点击下载后会报：{errMsg: “invokeMiniProgramAPI:ok“}
                                        url: `../application/${preViewPage}?record=${JSON.stringify({url: encodeURIComponent(elem.getAttribute("url")), name: elem.getAttribute("attachName"), isVideo: isVideo})}`
                                    })
                                } else {
                                    uni.navigateTo({
                                        url: `/application/${preViewPage}?record=${JSON.stringify({url: encodeURIComponent(elem.getAttribute("url")), name: elem.getAttribute("attachName"), isVideo: isVideo})}`
                                    });
                                }
                            });
                        } else {
                            uni.navigateTo({
                                url: `/application/${preViewPage}?record=${JSON.stringify({url: encodeURIComponent(elem.getAttribute("url")), name: elem.getAttribute("attachName"), isVideo: isVideo})}`
                            });
                        }
                    } else {
                        if (window.top != window) {
                            console.log('elem.getAttribute("url")', elem.getAttribute("url"));
                            // uniapp的h5方式运行于webview中，还可以通过一些特征，进一步判断是否运行于uniapp的iframe内，如 window.top的body中是否含有class: uni-body
                            uni.navigateTo({
                                url: `/application/${preViewPage}?record=${JSON.stringify({url: encodeURIComponent(elem.getAttribute("url")), name: elem.getAttribute("attachName"), isVideo: isVideo})}`
                            });
                        } else {
                            // wap 运行，不在uniapp的webview内
                            mui.openWindow({
                                "url": url
                            })
                        }
                    }
                }
            });

            $(".mui-content").off('tap', '.att_download').on('tap', '.att_download', function (event) {
                var elem = this;
                var li = elem.parentNode.parentNode;
                var url = jQuery(li).find('.attFile').attr('link');
                if (!url) {
                    url = jQuery(li).find('.att_preview').attr('link');
                }

                if (mui.os.plus) {
                    var btnArray = ['是', '否'];
                    mui.confirm('您确定要下载么？', '', btnArray, function(e) {
                        if (e.index == 0) {
                            var rootPath = self.getContextPath();
                            // 链接为../../public/android/flow/getFile，故需转换，否则会报400错误
                            var p = url.indexOf("/public/");
                            if (p!=-1) {
                                url = url.substring(p);
                            }
                            url = rootPath + url;
                            var dtask = plus.downloader.createDownload(url, {}, function (d, status) {
                                if (status == 200) {
                                    // 调用第三方应用打开文件
                                    plus.runtime.openFile(d.filename, {}, function (e) {
                                        alert('打开失败');
                                    });
                                } else {
                                    alert("下载失败: " + status);
                                }
                            });
                            dtask.start();
                        }
                    });
                }
                else {
                    let ua = navigator.userAgent;
                    if (ua.match(/MicroMessenger/i) == "MicroMessenger") {
                        wx.miniProgram.getEnv(function (res) {
                            console.log("当前环境：" + JSON.stringify(res));
                            if (res.miniprogram) {
                                wx.miniProgram.navigateTo({
                                    // url: `/pages/application/wxDownload?url=${encodeURIComponent(url)}`
                                    // 需将绝对路径换成相对路径，否则点击下载后会报：{errMsg: “invokeMiniProgramAPI:ok“}
                                    url: `../application/wxDownload?url=${encodeURIComponent(url)}`
                                })
                            } else {
                                mui.openWindow({
                                    "url": url
                                })
                            }
                        });
                    } else {
                        mui.openWindow({
                            "url": url
                        })
                    }
                }
            });
            $(".mui-content").off('tap', '.circle_read').on('tap', '.circle_read', function (event) {
                var id = this.getAttribute('attId');
                uni.navigateTo({
                    url: `/application/annotations?record=${JSON.stringify({id: id})}`
                });
            });

            $(".mui-content").off('tap', '.inRed').on('tap', '.inRed', function (event) {
                var flowId = jQuery("#flowId").val();
                var attachId = this.getAttribute('attId');
                var opts = '<option value=""></option>';

                $.ajax({
                    async: false,
                    type: "post",
                    url: "../../flow/getTemplates",
                    data: {
                        skey: skey,
                        flowId: flowId,
                    },
                    dataType: "json",
                    beforeSend: function (XMLHttpRequest) {
                        jQuery.myloading();
                    },
                    complete: function (XMLHttpRequest, status) {
                        jQuery.myloading("hide");
                    },
                    success: function (res, status) {
                        if (res.code == 200) {
                            var data = res.data;
                            for (var i in data) {
                                opts += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                            }
                        }
                    },
                    error: function (XMLHttpRequest, textStatus) {
                        alert(XMLHttpRequest.responseText);
                    }
                });

                var strHtml = '';
                strHtml += '<div class="mui-input-row">';
                strHtml += '<label>模板</label>';
                strHtml += '</div>';
                strHtml += '<div style="text-align: center" class="mui-input-row mui-select">';
                strHtml += '<select id="templates">' + opts + '</select>';
                strHtml += '</div>';
                strHtml += '<div class="mui-button-row" style="margin-top:10px;">';
                strHtml += '<button class="mui-btn mui-btn-primary" id="inred-btn" type="button">确认</button>';
                strHtml += '</div>';

                var pop = new Popup({contentType: 2, isReloadOnClose: false, width: 340, height: 300});
                pop.setContent("contentHtml", strHtml);
                pop.setContent("title", "请选择模板");
                pop.build();
                pop.show();
                setTimeout(function() {
                    jQuery("#templates").css("visibility", "visible");
                }, 100);
                // 使弹出对话框的背景色为白色
                jQuery('#dialogBox').css('background-color', '#fff');
                mui(".mui-button-row").on("tap", "#inred-btn", function () {
                    var templateId = jQuery("#templates").val();
                    if (templateId == '') {
                        mui.toast('请选择模板');
                        return;
                    }

                    $.ajax({
                        async: false,
                        type: "post",
                        url: "../../flow/convertToRedDocument",
                        data: {
                            skey: skey,
                            flowId: flowId,
                            attachId: attachId,
                            templateId: templateId,
                        },
                        dataType: "json",
                        success: function (res, status) {
                            mui.toast(res.msg);
                            if (res.code == 200)
                                window.location.reload();
                        },
                        beforeSend: function (XMLHttpRequest) {
                            jQuery.myloading();
                        },
                        complete: function (XMLHttpRequest, status) {
                            jQuery.myloading("hide");
                        },
                        error: function (XMLHttpRequest, textStatus) {
                            alert(XMLHttpRequest.responseText);
                        }
                    });

                    pop.close();
                });
            });

            $(".mui-content").off('tap', '.seal').on('tap', '.seal', function (event) {
                var flowId = jQuery("#flowId").val();
                var attachId = this.getAttribute('attId');
                var opts = '<option value=""></option>';

                $.ajax({
                    async: false,
                    type: "post",
                    url: "../../flow/getStamps",
                    data: {
                        skey: skey,
                        flowId: flowId,
                    },
                    dataType: "json",
                    beforeSend: function (XMLHttpRequest) {
                        jQuery.myloading();
                    },
                    complete: function (XMLHttpRequest, status) {
                        jQuery.myloading("hide");
                    },
                    success: function (res, status) {
                        if (res.code == 200) {
                            var data = res.data;
                            for (var i in data) {
                                opts += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                            }
                        }
                    },
                    error: function (XMLHttpRequest, textStatus) {
                        alert(XMLHttpRequest.responseText);
                    }
                });

                var strHtml = '';
                strHtml += '<div class="mui-input-row">';
                strHtml += '<label>印章</label>';
                strHtml += '</div>';
                strHtml += '<div style="text-align: center" class="mui-input-row mui-select">';
                strHtml += '<select id="stamps">' + opts + '</select>';
                strHtml += '</div>';
                strHtml += '<div class="mui-input-row">';
                strHtml += '<label>密码</label>';
                strHtml += '</div>';
                strHtml += '<div style="text-align: center" class="mui-input-row">';
                strHtml += '<input id="pwd" name="pwd" type="password"/>';
                strHtml += '</div>';
                strHtml += '<div class="mui-button-row" style="margin-top:10px;">';
                strHtml += '<button class="mui-btn mui-btn-primary" id="stamp-btn" type="button">确认</button>';
                strHtml += '</div>';

                var pop = new Popup({contentType: 2, isReloadOnClose: false, width: 340, height: 300});
                pop.setContent("contentHtml", strHtml);
                pop.setContent("title", "请选择印章");
                pop.build();
                pop.show();
                setTimeout(function() {
                    jQuery("#stamps").css("visibility", "visible");
                }, 100);
                // 使弹出对话框的背景色为白色
                jQuery('#dialogBox').css('background-color', '#fff');
                mui(".mui-button-row").on("tap", "#stamp-btn", function () {
                    var stampId = jQuery("#stamps").val();
                    if (stampId == '') {
                        mui.toast('请选择印章');
                        return;
                    }
                    if (jQuery('#pwd').val() == '') {
                        mui.toast('请输入密码');
                        return;
                    }

                    var isPwdValid = false;
                    $.ajax({
                        async: false,
                        type: "post",
                        url: "../../flow/macro/checkPwd",
                        data: {
                            skey: skey,
                            pwd: jQuery('#pwd').val(),
                        },
                        dataType: "json",
                        success: function (res, status) {
                            if (res.data.res == 1) {
                                mui.toast('密码错误');
                            } else {
                                isPwdValid = true;
                            }
                        },
                        beforeSend: function (XMLHttpRequest) {
                        },
                        complete: function (XMLHttpRequest, status) {
                        },
                        error: function (XMLHttpRequest, textStatus) {
                            alert(XMLHttpRequest.responseText);
                        }
                    });

                    if (!isPwdValid)
                        return;

                    $.ajax({
                        async: false,
                        type: "post",
                        url: "../../flow/sealDocument",
                        data: {
                            skey: skey,
                            flowId: flowId,
                            attachId: attachId,
                            stampId: stampId,
                        },
                        dataType: "json",
                        success: function (res, status) {
                            mui.toast(res.msg);
                            if (res.code == 200) {
                                window.location.reload();
                                pop.close();
                            }
                        },
                        beforeSend: function (XMLHttpRequest) {
                        },
                        complete: function (XMLHttpRequest, status) {
                        },
                        error: function (XMLHttpRequest, textStatus) {
                            alert(XMLHttpRequest.responseText);
                        }
                    });
                });
            });
        },
        formatDateTime: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours();
            h = h < 10 ? ('0' + h) : h;
            var minute = date.getMinutes();
            minute = minute < 10 ? ('0' + minute) : minute;
            var second = date.getSeconds();
            second = second < 10 ? ('0' + second) : second;
            return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
        },
        formatDate: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? '0' + m : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            return y + '-' + m + '-' + d;
        },
        bindEvent: function (formCode, isMobileForbidDownload) {
            var self = this;
            var content = self.element;
            var formSelector = self.options.formSelector;
            var skey = self.options.skey;
            // 日期选择控件
            $(formSelector).on("tap", ".date_btn", function () {
                var optionsJson = this.getAttribute('data-options') || '{}';
                var options = JSON.parse(optionsJson);
                var id = this.getAttribute('id');
                var par = this.parentNode;
                var time_input = par.querySelector(".input-icon");
                var picker = new $.DtPicker(options);
                picker.show(function (rs) {
                    if (options.type == "date") {
                        jQuery(time_input).val(rs.value);
                    } else {
                        jQuery(time_input).val(rs.value + ":00");
                    }
                    picker.dispose();
                });
            });
            // 签名框
            var isIos = false;
            if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                isIos = true;
            } else if (/(Android)/i.test(navigator.userAgent)) {
            } else {
            }

            // ios上面会先置入插入点，再点一次才能弹出
            $(formSelector).on("tap", ".signInput", function () {
                openSignIn(this, skey);
            });

            $(formSelector).on("tap", ".sign-img-btn", function () {
                openSignInImg(this, skey);
            });

            // 表单域选择
            $(formSelector).on("tap", ".moduleSelect", function () {
                openModuleField(this, skey);
            });
            $(formSelector).on("tap", ".myflow-select", function () {
                openFlowSelectWin(this, skey);
            });
            $(formSelector).on("tap", ".module-field-select", function () {
                openModuleShow(this, skey);
            });
            $(formSelector).on("tap", ".dept-select-win", function () {
                openDeptWin(this, skey);
            });

            $(formSelector).on("tap", ".user-select-win", function () {
                //处理
                selectUserWin(this, false, '', self.options.skey);
            });
            $(formSelector).on("tap", ".user-multi-select-win", function () {
                //处理
                selectUserWin(this, true, '', self.options.skey);
            });

            // 嵌套表按钮
            $(formSelector).on("tap", ".nestSheetSelect", function () {
                openNestSheet(this, skey);
            });
            $(formSelector).on("tap", ".attFile", function () {
                var url = jQuery(this).attr("link");
                var ext = jQuery(this).attr("ext");
                if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp") {
                    var w=0, h=0;
                    if (this.tagName=="IMG") { // 图像宏控件
                        w = jQuery(this).width();
                        h = jQuery(this).height();
                    }
                    console.log('url', url);
                    self.showImg(url, w, h);
                } else {
                    if (isMobileForbidDownload)
                        return;
                    if (mui.os.plus) {
                        var btnArray = ['是', '否'];
                        mui.confirm('您确定要下载么？', '', btnArray, function(e) {
                            if (e.index == 0) {
                                var rootPath = self.getContextPath();
                                // 链接为../../public/android/flow/getFile，故需转换，否则会报400错误
                                var p = url.indexOf("/public/");
                                if (p!=-1) {
                                    url = url.substring(p);
                                }
                                url = rootPath + url;
                                var dtask = plus.downloader.createDownload(url, {}, function (d, status) {
                                    if (status == 200) {
                                        // 调用第三方应用打开文件
                                        plus.runtime.openFile(d.filename, {}, function (e) {
                                            alert('打开失败');
                                        });
                                    } else {
                                        alert("下载失败: " + status);
                                    }
                                });
                                dtask.start();
                            }
                        });
                    }
                    else {
                        let ua = navigator.userAgent;
                        if (ua.match(/MicroMessenger/i) == "MicroMessenger") {
                            wx.miniProgram.getEnv(function (res) {
                                console.log("当前环境：" + JSON.stringify(res));
                                if (res.miniprogram) {
                                    wx.miniProgram.navigateTo({
                                        // url: `/pages/application/wxDownload?url=${encodeURIComponent(url)}`
                                        // 需将绝对路径换成相对路径，否则点击下载后会报：{errMsg: “invokeMiniProgramAPI:ok“}
                                        url: `../application/wxDownload?url=${encodeURIComponent(url)}`
                                    })
                                } else {
                                    mui.openWindow({
                                        "url": url
                                    })
                                }
                            });
                        } else {
                            mui.openWindow({
                                "url": url
                            })
                        }
                    }
                }
            });

            $(formSelector).on("tap", ".icon-location", function () {
                openBaiduMap(this);
            });

            $(formSelector).on("tap", ".icon-location-td", function () {
                openTdMap(this);
            });

            $(formSelector).on("tap", ".sign_btn", function() {
                openWritePadWin(this, skey);
            });

            $(formSelector).on("tap", ".btn-custom", function() {
                handleBtnClick(this, skey, self.options.moduleCode);
            });

            $(formSelector).on('tap', '.flow-title', function (event) {
                console.log('tap flow-title');
                var elem = this;
                if (elem.getAttribute("flowId")) {
                    if (mui.os.plus) {
                        uni.navigateTo({
                            url: `/application/processShow?record=${JSON.stringify({flowId: elem.getAttribute("flowId")})}`
                        });
                    } else {
                        // H5中没问题，app按下面的方式打开后，没有标题及后退按钮
                        mui.openWindow({
                            "url": "../../m/flow/flowShow?flowId=" + elem.getAttribute("flowId") + "&skey=" + skey
                        })
                    }
                }
            });
            console.log('bind event end');

            $(formSelector).on("tap", ".file-plus", function() {
                var code = jQuery(this).attr('code');
                var str = '<div><input type="file" name="' + code + '" id="' + code + '" class="atts-file" style="margin-top:15px" /><span code="' + code + '" class="file-minus">-</span></div>';
                jQuery('#attsBox' + code).append(str);
            });

            $(formSelector).on("tap", ".file-minus", function() {
                jQuery(this).parent().remove();
            });

            var uploaderCount = 0;
            jQuery('.uploader-ctl').each(function() {
                // if (uploaderCount == 0) {
                //     includFile(getContextPath() + "/weixin/js/macro/", ['macro_uploader_ctl.js']);
                // }

                var that = this;
                // 需延时后mui.Uploader才能被incloudFile初始化成功
                setTimeout(function() {
                    var options = {
                        fieldName: that.getAttribute('name')
                    };
                    var uploader = new mui.Uploader(this, options);
                    uploader.initUploaderCtl();
                    uploaderCtlArr.push(uploader);
                }, 100);
                uploaderCount++;
            })

            lowerToUpper();// 大小写金额转换
            initCalculator();// 计算控件初始化
            onIdCardChange(); // 绑定身份证变化事件
            onUserSelectWinChange(formCode); // 绑定用户选择窗体宏控件的变化以进行映射
        },
        showImg: function (path, width, height) {
            var w = 964, h = 1024;
            if (width && height) {
                w = width;
                h = height;
            }
            var openPhotoSwipe = function () {
                console.log('path', path, 'w', w, 'h', h);
                var pswpElement = jQuery('.pswp')[0];
                var items = [{
                    // src格式为../../public/showImg.do?path="+encodeURI(path),
                    src: path,
                    w: w,
                    h: h
                }
                ];
                // define options (if needed)
                var options = {
                    // history & focus options are disabled on CodePen
                    history: false,
                    focus: false,
                    tapToClose: false,
                    showAnimationDuration: 0,
                    hideAnimationDuration: 0
                };
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
                gallery.init();
            };
            openPhotoSwipe();
        },
        getFileImg: function (ext) {
            var _fname = "";
            if ("jpe,jpeg,gif,bmp,jpg,png".indexOf(ext) != -1) {
                _fname = "png.png";
            } else if ("doc,docx,wps".indexOf(ext) != -1) {
                _fname = "word.png";
            } else if ("xls,xlsx".indexOf(ext) != -1) {
                _fname = "excel.png";
            } else if ("pdf".indexOf(ext) != -1) {
                _fname = "pdf.png";
            } else if ("ppt,pptx".indexOf(ext) != -1) {
                _fname = "ppt.png";
            } else if ("txt".indexOf(ext) != -1) {
                _fname = "txt.png";
            } else if ("avi,mov,asf,wmv,3gp,mp4,rmvb,flv".indexOf(ext) != -1) {
                _fname = "mp4.png";
            } else if ("mp3,wma".indexOf(ext) != -1) {
                _fname = "mp3.png";
            } else if ("zip,rar".indexOf(ext) != -1) {
                _fname = "zip.png";
            } else {
                _fname = "other.png";
            }
            return _fname;
        },
        writeJS: function(jsFilePath) {
            // document.write("<script language='javascript' src='" + jsFilePath + "'></script>");
            var head = document.getElementsByTagName('head')[0];
            var script = document.createElement('script');
            script.src = jsFilePath;
            head.appendChild(script);
        },
        getContextPath: function () {
            var strFullPath = document.location.href;
            var strPath = document.location.pathname;
            var pos = strFullPath.indexOf(strPath);
            var prePath = strFullPath.substring(0, pos);
            var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
            // 有的服务器上会在路径中带上weixin，如contextPath为：http://****.com/weixin
            var contextPath = prePath + postPath;
            var	p = contextPath.indexOf("/weixin");
            if (p!=-1) {
                contextPath = contextPath.substring(0, p);
            }
            return contextPath;
        }
    });
})(mui, document, window)
